<template>
  <van-dialog
    v-model="obj._visible"
    :title="title"
    :width="width"
    :show-cancel-button="cancelText?true:false"
    :show-confirm-button="confimText?true:false"
    :cancel-button-text="cancelText"
    :confirm-button-text="confimText"
    close-on-popstate
    close-on-click-overlay
    :before-close="beforeCloseCallback"
    @confirm="confirmClick"
  >
    <slot></slot>
  </van-dialog>
</template>

<script>
import api from "@/api/api";
export default {
  props: {
    obj: {// InputObj
      type: Object,
      default: function () {
        return api.createInputObj();
      }
    },

    title: {// 对话框标题
      type: String,
      default: "提示"
    },

    confimText: {// 确定按钮的文字，null则不显示
      type: String,
      default: "确定"
    },

    cancelText: {// 取消按钮的文字，null则不显示
      type: String,
      default: "取消"
    },

    width: {// 对话框宽度
      type: String,
      default: "80%"
    }
  },

  methods: {
    beforeCloseCallback(action, done) {
      if (action == "confirm") {
        done(false);
      } else {
        done();
      }
    },

    confirmClick() {
      this.$emit("click");
    }
  }
}
</script>